package com.repair.worker.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.repair.api.worker.constant.WorkerOperateType;
import com.repair.base.exception.SystemErrorCode;
import com.repair.base.exception.SystemException;
import com.repair.worker.mapper.WorkerOperateStreamMapper;
import com.repair.worker.pojo.entity.Worker;
import com.repair.worker.pojo.entity.WorkerOperateStream;
import com.repair.worker.service.WorkerOperateStreamService;
import org.springframework.stereotype.Service;

/**
 * Created by IntelliJ IDEA.
 *
 * @author zq
 * @version 1.0
 * @create 2024-09-28 19:11
 * @since jdk1.8
 */
@Service
public class WorkerOperateStreamServiceImpl extends ServiceImpl<WorkerOperateStreamMapper, WorkerOperateStream> implements WorkerOperateStreamService {
    @Override
    public long insertStream(Worker worker, WorkerOperateType type) {
        WorkerOperateStream workerOperateStream = new WorkerOperateStream();
        workerOperateStream.setParam(JSON.toJSONString(worker));
        workerOperateStream.setType(type.name());
        workerOperateStream.setWorkerId(worker.getId().toString());
        int i = baseMapper.insert(workerOperateStream);
        if (i == 0) {
            throw new SystemException(SystemErrorCode.INSERT_FAILED);
        }
        return 1;
    }
}
